package com.nineclock.message.listener;

import com.nineclock.message.service.MessageService;
import com.nineclock.message.pojo.NcMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * messagePushTopic: 与推送时使用的标题是一致的
 *
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Component
@Slf4j
@RocketMQMessageListener(topic = "messagePushTopic" , consumerGroup = "messagePushConsumer")
public class MsgConsumerListener implements RocketMQListener<NcMessage> {



    @Autowired
    MessageService messageService;

    /**
     * 把消息推送给主管理员
     *
     * @param message
     */
    @Override
    public void onMessage(NcMessage message) {
        try {
            log.info(message.getApplyUsername() +"申请加入企业，由管理员" + message.getApproveUsername() +"审批");
            //推送消息
            messageService.pushSingleMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
